package tj.warning.pull.config;

import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;


@Configuration
@MapperScan(basePackages = {"tj.warning.pull.mapper.report3"}, sqlSessionFactoryRef = "sqlSessionFactoryReport3")
public class Report3MybatisConfiguration {
    @Bean(name = {"report3DB"})
    @ConfigurationProperties(prefix = "spring.datasource.report3")
    public DataSource dataSource3() {
        return DataSourceBuilder.create().build();
    }

    @Bean({"sqlSessionFactoryReport3"})
    public SqlSessionFactory sqlSessionFactoryReport3() throws Exception {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(dataSource3());
        factoryBean.setConfiguration((new MybatisProperties()).getConfiguration());
        factoryBean.setMapperLocations((new PathMatchingResourcePatternResolver()).getResources("classpath:mapper/report3/*.xml"));
        return factoryBean.getObject();
    }

    @Bean({"sqlSessionTemplateReport3"})
    public SqlSessionTemplate sqlSessionTemplateReport3() throws Exception {
        return new SqlSessionTemplate(sqlSessionFactoryReport3());
    }
}